﻿/*
 *=====================================================================
 * Name    : AutoEditUI
 * Author  : LCFC RD SS
 * Copyright (c) 2012 - 2019, Hefei LCFC Information Technology Co.Ltd.
 *=====================================================================
 */

using MK;
using System;
using System.Configuration;

namespace AutoEditUI
{
    internal class APPConfigure
    {
        public static string AckNameType { get; internal set; }
        public static string MESPath { get; internal set; }
        public static string ProfilePath { get; private set; }
        public static string PicPath { get; private set; }
        public static string IPPre { get; private set; }
        public static bool MFGOn { get; private set; }
        public static bool b_MesVersionCheck { get; private set; }
        public static bool IsSizeAuto { get; private set; }
        public static string SoftWareType { get; private set; }
        public static bool ProfileVersionCheck { get; private set; }
        public static bool b_DefaultPageSettings { get; private set; }
        public static double DPITimes { get; private set; }
        public static double BigLeft { get; private set; }
        public static double BigDown { get; private set; }
        public static double BigRight { get; private set; }
        public static double BigTop { get; private set; }
        public static bool XpsPrintOn { get; private set; }
        public static bool IMEIOn { get; private set; }
        public static bool MFGSizeCheck { get; private set; }
        public static bool XAMLDebug { get; private set; }

        public static string PrinterName { get; private set; }
        public static double IconW { get; internal set; }
        public static double IconH { get; internal set; }
        public static double QRWH { get; internal set; }
        public static double LineW { get; internal set; }
        public static double LineH { get; internal set; }
        public static double BarcodeW { get; internal set; }
        public static double BarcodeH { get; internal set; }
        public static double CanvasW { get; internal set; }
        public static double CanvasH { get; internal set; }
        public static double TextW { get; internal set; }
        public static double TextH { get; internal set; }

        internal static void RefreshConfigure(MainWindow mainWindow)
        {
            string Str_MESPath;
            string Str_ProfilePath;
            string Str_PicPath;
            try
            {
                LogHelper.Log("【GetConfigure Start】");
                ConfigurationManager.RefreshSection("appSettings");
                APPConfigure.IPPre = ConfigurationManager.AppSettings["Str_IPPre"];
                APPConfigure.MFGOn = MFGUtil.GetEnvByIP(APPConfigure.IPPre);
              //  Utils.APPConfigureMFGOn = APPConfigure.MFGOn;
                if (APPConfigure.MFGOn)
                {
                    mainWindow.Title = "MES【" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString() + "】" + "  程序版本：" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + ""; ;
                    LogHelper.Log("***** MFG Mode ***** ");
                    Str_MESPath = "Str_MFGMESPath";
                    Str_ProfilePath = "Str_MFGProfilePath";
                    Str_PicPath = "Str_MFGPicPath";
                }
                else
                {
                    mainWindow.Title = "【" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString() + "】" + "  程序版本：" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + ""; ;
                    LogHelper.Log("***** Cert Mode ***** ");
                    Str_MESPath = "Str_CertMESPath";
                    Str_ProfilePath = "Str_CertProfilePath";
                    Str_PicPath = "Str_CertPicPath";
                }
                try
                {
                    //APPConfigureDebug.splaserwhite = Convert.ToDouble(ConfigurationManager.AppSettings["Double_splaserwhite"]);
                    APPConfigure.b_MesVersionCheck = Convert.ToBoolean(ConfigurationManager.AppSettings["Bool_MesVersionCheck"]);

               
                    APPConfigure.IsSizeAuto = Convert.ToBoolean(ConfigurationManager.AppSettings["Bool_AutoSize"]);

                    APPConfigure.SoftWareType = ConfigurationManager.AppSettings["Str_SoftWareType"];
                   

                }
                catch (Exception ee)
                {

                    APPConfigure.b_MesVersionCheck = false;

                    LogHelper.Log(ee.ToString() + "***** Cert Mode  Exception ***** ");
                }

                try
                {
                    APPConfigure.ProfileVersionCheck = Convert.ToBoolean(ConfigurationManager.AppSettings["Bool_ProfileVersionCheck"]);
                }
                catch (Exception)
                {
                    APPConfigure.ProfileVersionCheck = false;
                }

             
                try
                {
                    APPConfigure.b_DefaultPageSettings = Convert.ToBoolean(ConfigurationManager.AppSettings["Bool_DefaultPageSettings"]);
                }
                catch (Exception)
                {
                    APPConfigure.b_DefaultPageSettings = false;
                }


                APPConfigure.MESPath = ConfigurationManager.AppSettings[Str_MESPath];
                APPConfigure.ProfilePath = ConfigurationManager.AppSettings[Str_ProfilePath];
                APPConfigure.PicPath = ConfigurationManager.AppSettings[Str_PicPath];
                LogHelper.Log("【MESPath】 " + APPConfigure.MESPath);
                LogHelper.Log("【ProfilePath】 " + APPConfigure.ProfilePath);
                LogHelper.Log("【PicPath】 " + APPConfigure.PicPath);
                APPConfigure.DPITimes = Convert.ToDouble(ConfigurationManager.AppSettings["Double_DPITimes"]);
                APPConfigure.BigLeft = Convert.ToDouble(ConfigurationManager.AppSettings["Double_BigLeft"]);
                APPConfigure.BigDown = Convert.ToDouble(ConfigurationManager.AppSettings["Double_BigDown"]);
                APPConfigure.BigRight = Convert.ToDouble(ConfigurationManager.AppSettings["Double_BigRight"]);
                APPConfigure.BigTop = Convert.ToDouble(ConfigurationManager.AppSettings["Double_BigTop"]);

              
               
                MBLFontSize.FontSizeNormal = Convert.ToDouble(ConfigurationManager.AppSettings["Int_FontSizeNormal"]);
                MBLFontSize.FontSizeSmall = Convert.ToDouble(ConfigurationManager.AppSettings["Int_FontSizeSmall"]);
                MBLFontSize.FontSizeBig = Convert.ToDouble(ConfigurationManager.AppSettings["Int_FontSizeBig"]);
                MBLFontSize.TNBFontSizeNormal = Convert.ToDouble(ConfigurationManager.AppSettings["Int_TNBFontSizeNormal"]);
                MBLFontSize.TNBFontSizeSmall = Convert.ToDouble(ConfigurationManager.AppSettings["Int_TNBFontSizeSmall"]);
                MBLFontSize.TNBFontSizeBig = Convert.ToDouble(ConfigurationManager.AppSettings["Int_TNBFontSizeBig"]);
                
               
                APPConfigure.XpsPrintOn = Convert.ToBoolean(ConfigurationManager.AppSettings["Bool_XpsPrintOn"]);
                APPConfigure.IMEIOn = Convert.ToBoolean(ConfigurationManager.AppSettings["Bool_IMEIOn"]);
                APPConfigure.MFGSizeCheck = Convert.ToBoolean(ConfigurationManager.AppSettings["Bool_MFGSizeCheck"]);
                APPConfigure.XAMLDebug = Convert.ToBoolean(ConfigurationManager.AppSettings["Bool_XAMLDebug"]);

                APPConfigure.IconW = Convert.ToDouble(ConfigurationManager.AppSettings["IconW"]);
                APPConfigure.IconH = Convert.ToDouble(ConfigurationManager.AppSettings["IconH"]);
                APPConfigure.QRWH = Convert.ToDouble(ConfigurationManager.AppSettings["QRWH"]);
                APPConfigure.LineW = Convert.ToDouble(ConfigurationManager.AppSettings["LineW"]);
                APPConfigure.LineH = Convert.ToDouble(ConfigurationManager.AppSettings["LineH"]);
                APPConfigure.BarcodeW  = Convert.ToDouble(ConfigurationManager.AppSettings["BarcodeW"]);
                APPConfigure.BarcodeH  = Convert.ToDouble(ConfigurationManager.AppSettings["BarcodeH"]);
                APPConfigure.CanvasW  = Convert.ToDouble(ConfigurationManager.AppSettings["CanvasW"]);
                APPConfigure.CanvasH  = Convert.ToDouble(ConfigurationManager.AppSettings["CanvasH"]);
                APPConfigure.TextW = Convert.ToDouble(ConfigurationManager.AppSettings["TextW"]);
                APPConfigure.TextH  = Convert.ToDouble(ConfigurationManager.AppSettings["TextH"]);


                APPConfigure.PrinterName = ConfigurationManager.AppSettings["Str_PrinterName1"];
             
                LogHelper.Log("【Get Configure Finish】");
             
                return;
            }
            catch (Exception ee)
            {
                System.Windows.Forms.MessageBox.Show("配置文件出错" + ee.ToString());
                throw;
            }
        }
    }

    public class MBLFontSize
    {
        public static double FontSizeNormal { get; set; }
        public static double FontSizeSmall { get; set; }
        public static double FontSizeBig { get; set; }
        public static double TNBFontSizeNormal { get; set; }
        public static double TNBFontSizeSmall { get; set; }
        public static double TNBFontSizeBig { get; set; }
    }
}